package com.tuanzi.loan.business.repository.templateConf.impl;

import com.tuanzi.loan.business.entity.templateConf.LoanApiModelItembasisEntity;
import com.tuanzi.loan.business.repository.templateConf.custom.LoanApiModelItembasisRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.tuanzi.loan.generated.jooq.loan.Tables.LOAN_API_MODEL_ITEM;
import static com.tuanzi.loan.generated.jooq.loan.Tables.LOAN_API_MODEL_ITEMBASIS;

@Repository
public class LoanApiModelItembasisRepositoryImpl extends JOOQBaseRepository implements LoanApiModelItembasisRepositoryCustom {
    @Override
    public List<LoanApiModelItembasisEntity> getModelItemBasisListByApiId(Long apiId) {
        fields(LOAN_API_MODEL_ITEM.ID, LOAN_API_MODEL_ITEMBASIS.TITLE);
        innerJoin(LOAN_API_MODEL_ITEM, LOAN_API_MODEL_ITEM.ITEM_BASIS_ID.eq(LOAN_API_MODEL_ITEMBASIS.ID));
        eq(LOAN_API_MODEL_ITEM.API_ID, apiId);
        orderBy(LOAN_API_MODEL_ITEM.ID, Sort.Direction.ASC);

        return search(LoanApiModelItembasisEntity.class);
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_API_MODEL_ITEMBASIS;
    }
}
